package org.ccay.log.service.impl;

import javax.inject.Named;

import org.ccay.core.cache.ICacheNotifyHandler;
import org.ccay.core.cache.ehcache.CacheEvent;
import org.ccay.core.exception.ApplicationException;
import org.ccay.core.log.CcayLoggerFactory;
import org.ccay.core.log.ILogger;
import org.ccay.log.connection.impl.ConnectionLogStatusManager;
import org.ccay.registry.util.RegistryQueryUtil;


/**
 * 初始化Connection for Log module with EnableConnectionLog value,
 * @author chaowangbang
 * 2013-08-28
 */
@Named
public class ConnectionCacheNotifyHandler implements ICacheNotifyHandler{
	private static final ILogger logger = CcayLoggerFactory.getLogger(ConnectionCacheNotifyHandler.class);
	
	/* (non-Javadoc)
	 * @see www.ccay.org.ccay.core.dispatcher.IEventHandler#execute(java.lang.Object, www.ccay.org.ccay.core.dispatcher.IEventArgs)
	 */
	public void execute(Object sender, CacheEvent args)throws ApplicationException {
		String switchValue = RegistryQueryUtil.getValue("Ccay.Logs.EnableConnectionLog");
		if("1".equals(switchValue)){
			ConnectionLogStatusManager.setLogEnabled(true);
			logger.debug("Value of EnableConnectionLog is "+switchValue);
			return;
		}
		ConnectionLogStatusManager.setLogEnabled(false);
		logger.debug("Value of EnableConnectionLog is "+switchValue);
		
	}

}
